package com.fzy.silntgym.weight.MSfab.models;

import android.app.ListActivity;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.widget.Switch;

import com.fzy.silntgym.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;

/**
 * Created by Gordon Wong on 7/18/2015.
 * 
 * AllNote model.
 */
public class AllNote {


	private static final String[] ACTIONS_PEOPLE = { "call", "email", "meet up with",
			"hang out with" };
	private static final String[] ACTIONS_OBJECTS = { "clean", "buy", "sell", "fix" };
	private static final String[] NAMES = { "Sherry", "Gordon", "Tom", "Kevin", "Brian", "Naomi",
			"Ali", "Jennifer" };
	private static final String[] OBJECTS = { "desk", "car", "motorcycle", "computer", "laptop" };
	private static final String WORDS = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.";
	private static final String[] CITIES = { "唐岛湾公园", "康大凤凰广场", "唐岛湾三楼活动室", "丁家河公园",
			"人民广场", "达利广场", "美乐购物广场","利群美食广场","马濠公园","北海公园","月亮湖公园" };

	private static final String[] LIST_TITLES = { "shopping", "to bring", "on sale", "look for",
			"buy", "get rid of" };
	private static final String[] LIST_DELIMITERS = { "•", "-" };
	private static final String[] LIST_GROCERIES = { "almond milk", "coconut water", "cucumber",
			"green apples" };
	private static final String[] LIST_CAMPING = { "lantern", "smores", "extra blankets",
			"warm socks", "first aid kit", "tent" };
	private static int ListNum = 0;
	private static final String TITLE0 = "欢迎来到无声广场讨论！";
	private static final String WORD0 = "点击下方加号写话题即可发表话题，但是需要通过省核才能显示，赶紧和大家聊聊吧！";
	private static final String TITLE1 ="老伙伴们来吧";
	private static final String WORD1 = "今晚我们进行新的课程联系，希望组员们别迟到";
	private static final String TITLE2 ="尚优理发赞助的广场舞挑战赛开始啦";
	private static final String WORD2 = "今晚19:00将进行广场舞比赛，届时有大量礼品赠送，快来参加吧！详询：1785XXXX2441";
	private static final String TITLE3 ="新的舞蹈动作编成啦";
	private static final String WORD3 = "一套适应小苹果BGM的舞蹈动作，感兴趣的联系本人QQ：42862182XXX，希望能和大家一起交流";
	private static final String TITLE4 = "招聘管理一名";
	private static final String WORD4 = "在本广场招聘一名领舞管理员，详询152XXXX2541";
	private static final String TITLE5 = "招聘员领舞者多名";
	private static final String WORD5 = "紧急招聘多名领舞，待遇面议，详询QQ：259818XXX";
	private static final String TITLE6 = "游园活动举办";
	private static final String WORD6 = "各种奖励和各种活动等着你哦，速速参加吧！";
	private static final int NUM_WORDS = 4;
	private static final int DATE_RANGE = -8;

	private String title;
	private String note;
	private String info;
	@DrawableRes
	private int infoImage;
	private int color;

	private AllNote(String title, String note, String info, int infoImage, int color) {
		this.title = title;
		this.note = note;
		this.info = info;
		this.infoImage = infoImage;
		this.color = color;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public int getInfoImage() {
		return infoImage;
	}

	public void setInfoImage(int infoImage) {
		this.infoImage = infoImage;
	}

	public int getColor() {
		return color;
	}

	public void setColor(int color) {
		this.color = color;
	}

	public static AllNote randomNote(Context context) {
		String title = "";
		String note = "";
		NoteInfo info = new NoteInfo("", 0);
		int color = getRandomColor(context);

		title = getRandomActivity(ListNum);
		note = getRandomWords(ListNum);
		info = getRandomInfo(context);

		return new AllNote(capitalize(title), note, info.info, info.infoImage, color);
	}

	private static String getRandomActivity(int ListNum) {
		String words = "";
		switch(ListNum){
			case 0:
				words = TITLE0;
				break;
			case 1:
				words = TITLE1;
				break;
			case 2:
				words = TITLE2;
				break;
			case 3:
				words = TITLE3;
				break;
			case 4:
				words = TITLE4;
				break;
			case 5:
				words = TITLE5;
				break;
			case 6:
				words = TITLE6;
				break;
			default:
				break;
		}
		return words;
	}

	private static String getRandomWords(int ListNum) {
		String words = "";
		switch(AllNote.ListNum++){
			case 0:
				words = WORD0;
				break;
			case 1:
				words = WORD1;
				break;
			case 2:
				words = WORD2;
				break;
			case 3:
				words = WORD3;
				break;
			case 4:
				words = WORD4;
				break;
			case 5:
				words = WORD5;
				break;
			case 6:
				words = WORD6;
				break;
			default:
				break;
		}
		return words;
	}

	private static String getRandomListTitle() {
		String title = getRandomString(true, LIST_TITLES);
		if (!TextUtils.isEmpty(title)) {
			title += ":";
		}
		return title;
	}

	private static String getRandomList() {
		String[] list = (String[]) getRandomItem(new Object[] { LIST_GROCERIES, LIST_CAMPING });
		String delimiter = getRandomString(true, LIST_DELIMITERS);
		if (!TextUtils.isEmpty(delimiter)) {
			delimiter += " ";
		}
		String listStr = "";
		for (int i = 0; i < list.length; i++) {
			listStr += delimiter + list[i];
			if (i != list.length - 1) {
				listStr += "\n";
			}
		}
		return listStr;
	}

	private static NoteInfo getRandomInfo(Context context) {
		NoteInfo[] infos = new NoteInfo[] { getRandomLocation() };
		return (NoteInfo) getRandomItem(infos);
	}

	private static NoteInfo getRandomDate(Context context) {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, (int) (Math.random() * DATE_RANGE));
		String date = DateFormat.getMediumDateFormat(context).format(cal.getTime());
		return new NoteInfo(date, R.drawable.ic_event_white_24dp);
	}
	//get city
	private static NoteInfo getRandomLocation() {
		String location = getRandomString(false, CITIES);
		return new NoteInfo(location, R.drawable.ic_place_white_24dp);
	}

	private static int getRandomColor(Context context) {
		int[] colors;
		if (Math.random() >= 0.6) {
			colors = context.getResources().getIntArray(R.array.note_accent_colors);
		} else {
			colors = context.getResources().getIntArray(R.array.note_neutral_colors);
		}
		return colors[((int) (Math.random() * colors.length))];
	}

	private static String capitalize(String str) {
		if (TextUtils.isEmpty(str)) {
			return str;
		}
		return Character.toUpperCase(str.charAt(0)) + str.substring(1);
	}

	private static String getRandomString(boolean includeEmpty, String[] strings) {
		if (includeEmpty) {
			ArrayList<String> stringsWithEmpty = new ArrayList<>(Arrays.asList(strings));
			stringsWithEmpty.add("");
			return (String) getRandomItem(stringsWithEmpty.toArray());
		}
		return (String) getRandomItem(strings);
	}

	private static Object getRandomItem(Object[] objs) {
		return objs[((int) (Math.random() * objs.length))];
	}

	private static class NoteInfo {

		private String info;
		private int infoImage;

		private NoteInfo(String info, int infoImage) {
			this.info = info;
			this.infoImage = infoImage;
		}

	}
}
